package com.forever.volleydemo;

import android.graphics.Bitmap;
import android.support.v4.util.LruCache;

import com.android.volley.toolbox.ImageLoader.ImageCache;

/**
 * 
 * 
 * 实现的图片缓存
 * @author wy
 *
 */
public class ImageCacheBitmap implements ImageCache {

	// 获得APP运行时最大内存
	private int maxMemory = (int) Runtime.getRuntime().maxMemory();

	private final LruCache<String, Bitmap> cache = new LruCache<String, Bitmap>(
			maxMemory / 8) {
		protected int sizeOf(String key, Bitmap value) {
			return value.getByteCount();
		};
	};

	@Override
	public Bitmap getBitmap(String url) {
		return cache.get(url);

	}

	@Override
	public void putBitmap(String url, Bitmap bitmap) {
		// 防止重复放
		if (cache.get(url) == null) {
			cache.put(url, bitmap);
		}

	}
}
